package com.lyy.king.tools.service.file.handler.excel;

import com.lyy.king.common.utils.exception.CheckParamException;
import com.lyy.king.tools.enums.ImportExcelOperatorTypeEnum;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassDescription:
 * @JdkVersion: 1.8
 * @Author: cdx
 * @Created: 2023/12/26 19:46
 */
public class ImportExcelOperatorEngineFactory {
    /**
     * 处理器 map
     */
    protected static Map<ImportExcelOperatorTypeEnum, ImportExcelOperatorEngine> importExcelOperatorEngineMap = new HashMap<>();

    /**
     * 获取执行引擎
     *
     * @param operatorType
     * @return
     */
    public static ImportExcelOperatorEngine get(ImportExcelOperatorTypeEnum operatorType) {
        ImportExcelOperatorEngine importExcelOperatorEngine = importExcelOperatorEngineMap.get(operatorType);
        CheckParamException.check(importExcelOperatorEngine != null, "Operator Engine 不存在,type:" + operatorType.getDesc());
        return importExcelOperatorEngine;
    }

    /**
     * 注册操作引擎
     *
     * @param operatorType
     * @param engine
     */
    public static void register(ImportExcelOperatorTypeEnum operatorType, ImportExcelOperatorEngine engine) {
        importExcelOperatorEngineMap.put(operatorType, engine);
    }

}
